<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文本字节大小计算器</title>
    <style>
        body {
            font-family: '微软雅黑', sans-serif;
            background-color: #f0f4f8;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            flex-direction: column;
        }

        .container {
            width: 80%;
            max-width: 600px;
            background-color: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }

        h1 {
            color: #3f51b5;
            text-align: center;
        }

        .input-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 20px;
        }

        input[type="text"] {
            width: 100%;
            padding: 12px;
            border-radius: 5px;
            border: 1px solid #ccc;
            font-size: 16px;
            margin-bottom: 20px;
            box-sizing: border-box;
            transition: border 0.3s;
        }

        input[type="text"]:focus {
            border-color: #3f51b5;
            outline: none;
        }

        .button-container {
            display: flex;
            justify-content: center;
            margin-top: 20px;
        }

        button {
            padding: 12px 24px;
            background-color: #3f51b5;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            margin: 0 10px;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #303f9f;
        }

        .result-container {
            margin-top: 20px;
            text-align: center;
            font-size: 18px;
            color: #333;
        }

        .status {
            font-size: 16px;
            color: #4caf50;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>文本字节大小计算器</h1>

        <div class="input-container">
            <label for="input-text">请输入文本：</label>
            <input type="text" id="input-text" placeholder="输入一些文本...">
        </div>

        <div class="button-container">
            <button onclick="calculateSize()">计算字节大小</button>
        </div>

        <div class="result-container" id="result-container">
            <div class="status">当前状态: <span>请输入文本并点击计算按钮</span></div>
            <div class="result">字节大小: <span id="byte-size">0</span> 字节</div>
        </div>
    </div>

    <script>
        // 计算字符串的字节大小
        const byteSize = str => new Blob([str]).size;

        // 计算字节大小并更新页面
        const calculateSize = () => {
            const inputText = document.getElementById('input-text').value;
            const resultContainer = document.getElementById('result-container');
            const byteSizeDisplay = document.getElementById('byte-size');
            const statusDisplay = resultContainer.querySelector('.status span');

            if (inputText.trim() === '') {
                statusDisplay.textContent = '请输入一些文本！';
                byteSizeDisplay.textContent = '0';
            } else {
                const size = byteSize(inputText);
                statusDisplay.textContent = '计算完成！';
                byteSizeDisplay.textContent = size;
            }
        };
    </script>

</body>

</html>